package enterprise.web.tookit.integration.email;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import enterprise.web.tookit.email.Email;
import enterprise.web.tookit.generic.GenericDaoImpl;

/**
 * @since 12/03/2013
 * 
 * @author regis rocha
 * 
 * @description Classe para realizar acesso aos dados de email.
 * 
 */
public class EmailDao extends GenericDaoImpl {

	/**
	 * Construtor para inicializar o entityManager.
	 * 
	 * @param EntityManager
	 */
	public EmailDao(EntityManager em) {
		super(em);
		this.entityManager = em;
	}

	/**
	 * serial version
	 */
	private static final long serialVersionUID = -8105501872666333929L;

	/**
	 * Attribute for entity manager
	 */
	private EntityManager entityManager;

	public Email obterConfiguracaoEmail() {

		final Query query = this.entityManager.createQuery("SELECT E FROM email E WHERE E.active=:active");

		query.setParameter("active", Boolean.TRUE);

		return (Email) query.getSingleResult();
	}
}